package org.oims.simpleserver.controllers.api.v1;

import org.oims.simpleserver.entities.FriendChatDetailItem;
import org.oims.simpleserver.entities.db.User;
import org.oims.simpleserver.entities.results.SimpleResult;
import org.oims.simpleserver.services.UserService;
import org.oims.simpleserver.utils.ReturnResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping(value = {"/api/v1/user"})
public class UserController {
    private UserService userService;

    @GetMapping(value = {"/user-chat-details"})
    public SimpleResult getFriendChatDetails(HttpSession session, HttpServletResponse resp){
        try {
            User user = (User) session.getAttribute("user");
            List<FriendChatDetailItem> list = userService.getFriendChatDetails(user.getMpNo());
//            List<FriendChatDetailItem> list = userService.getFriendChatDetails("+86-17513289887");
            return ReturnResultUtil.getDataResult(list);
        }catch (Exception e){
            e.printStackTrace();
            resp.setStatus(500);
            return ReturnResultUtil.getServerErrorResult();
        }
    }

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
}
